package com.crm.controller;

import com.crm.base.ResponseResult;
import com.crm.domain.dto.DeptDto;
import com.crm.domain.entity.Dept;
import com.crm.domain.vo.DeptTreeVo;
import com.crm.domain.vo.DeptVo;
import com.crm.domain.vo.TreeVo;
import com.crm.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("system/dept")
@Api(tags = "部门管理")
public class DeptConntroller {
    @Autowired
    private DeptService deptService;

    @GetMapping("/list")
    @ApiOperation("获取部门列表")
    public ResponseResult<List<DeptVo>> listDept(String deptName,Integer status){
        List<DeptVo> list = deptService.listDept(deptName,status);
        return ResponseResult.success(list);
    }

    @GetMapping("/treeselect")
    @ApiOperation("树形部门列表")
    public ResponseResult<List<DeptTreeVo>> treeSelectDept(){
        List<DeptTreeVo> treeVos = deptService.treeSelectDept();
        return ResponseResult.success(treeVos);
    }

    @GetMapping("/{id}")
    @ApiOperation("部门详情")
    public ResponseResult<DeptVo> getDept(@PathVariable("id") Integer id){
        DeptVo deptVo = deptService.getDept(id);
        return ResponseResult.success(deptVo);
    }

    @GetMapping("/list/exclude/{id}")
    @ApiOperation("查询除了自己子部门以外的其他外")
    public ResponseResult<List<DeptVo>> excludeDept(@PathVariable("id") Integer deptId){
        List<DeptVo> deptVos = deptService.excludeDept(deptId);
        return ResponseResult.success(deptVos);
    }

    @PostMapping("")
    @ApiOperation("新增部门")
    public ResponseResult addDept(@RequestBody DeptDto deptDto){
        deptService.addDept(deptDto);
        return ResponseResult.success();
    }
}
